//
//  CategoriesAndExtensionsTest.h
//  test_simple_project
//
//  分类和扩展语法特性测试文件
//  测试Category、Class Extension等Objective-C扩展机制
//

#import <Foundation/Foundation.h>

#pragma mark - 基础测试类

@interface CategoriesAndExtensionsTest : NSObject

// 基础属性
@property (strong, nonatomic) NSString *baseProperty;
@property (assign, nonatomic) NSInteger baseValue;

// 基础方法
- (void)performBasicOperation;
- (NSString *)getBasicInfo;

@end

#pragma mark - NSString分类扩展

/**
 * NSString的Category扩展
 * 演示如何为系统类添加自定义方法
 */
@interface NSString (StringValidation)

// 字符串验证方法
- (BOOL)isValidEmail;
- (BOOL)isValidPhoneNumber;
- (BOOL)isValidURL;
- (BOOL)containsOnlyNumbers;
- (BOOL)containsOnlyLetters;

// 字符串处理方法
- (NSString *)trimmedString;
- (NSString *)capitalizedFirstLetter;
- (NSString *)reversedString;
- (NSArray<NSString *> *)wordsArray;

// 字符串转换方法
- (NSString *)md5Hash;
- (NSString *)base64EncodedString;
- (NSString *)urlEncodedString;

@end

#pragma mark - NSArray分类扩展

/**
 * NSArray的Category扩展
 * 演示集合类的功能扩展
 */
@interface NSArray<ObjectType> (ArrayUtilities)

// 数组操作方法
- (NSArray<ObjectType> *)shuffledArray;
- (NSArray<ObjectType> *)uniqueObjects;
- (ObjectType)randomObject;
- (NSArray<ObjectType> *)arrayByRemovingObject:(ObjectType)object;

// 数组查询方法
- (BOOL)containsObjectPassingTest:(BOOL (^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate;
- (ObjectType)firstObjectPassingTest:(BOOL (^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate;
- (NSArray<ObjectType> *)objectsPassingTest:(BOOL (^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate;

// 数组统计方法
- (NSUInteger)countOfObjectsPassingTest:(BOOL (^)(ObjectType obj, NSUInteger idx, BOOL *stop))predicate;

@end

#pragma mark - UIView分类扩展（如果可用）

#if TARGET_OS_IOS
#import <UIKit/UIKit.h>

/**
 * UIView的Category扩展
 * 演示UI相关的分类扩展
 */
@interface UIView (FrameUtilities)

// 框架属性快捷访问
@property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGFloat centerX;
@property (nonatomic, assign) CGFloat centerY;

// 框架操作方法
- (void)setFrameWithX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height;
- (void)centerInSuperview;
- (void)centerHorizontallyInSuperview;
- (void)centerVerticallyInSuperview;

// 视图层次操作
- (void)removeAllSubviews;
- (UIView *)findSubviewOfClass:(Class)viewClass;
- (NSArray<UIView *> *)findAllSubviewsOfClass:(Class)viewClass;

@end
#endif

#pragma mark - 类扩展(Class Extension)

/**
 * CategoriesAndExtensionsTest的类扩展
 * 演示私有属性和方法的声明
 * 注意：类扩展通常在.m文件中声明，这里为了测试放在.h文件中
 */
@interface CategoriesAndExtensionsTest ()

// 私有属性
@property (strong, nonatomic) NSMutableArray *privateDataArray;
@property (strong, nonatomic) NSMutableDictionary *privateDataDictionary;
@property (assign, nonatomic) BOOL privateFlag;
@property (strong, nonatomic) dispatch_queue_t privateQueue;

// 私有方法声明
- (void)performPrivateOperation;
- (NSString *)generatePrivateIdentifier;
- (void)processPrivateData:(NSArray *)data;
- (BOOL)validatePrivateState;

// 私有计算属性
- (NSUInteger)privateDataCount;
- (NSString *)privateDataSummary;

@end

#pragma mark - 协议扩展

/**
 * 自定义协议用于分类扩展
 */
@protocol CategoryTestProtocol <NSObject>

@required
- (void)requiredCategoryMethod;
- (NSString *)requiredCategoryMethodWithParameter:(id)parameter;

@optional
- (void)optionalCategoryMethod;
- (BOOL)optionalCategoryMethodReturningBool;

@end

/**
 * 为现有类添加协议支持的分类
 */
@interface CategoriesAndExtensionsTest (ProtocolSupport) <CategoryTestProtocol>

// 协议方法的分类实现将在.m文件中
- (void)demonstrateProtocolSupport;

@end

#pragma mark - 多个分类扩展

/**
 * 数据处理相关的分类
 */
@interface CategoriesAndExtensionsTest (DataProcessing)

// 数据处理方法
- (void)processStringData:(NSArray<NSString *> *)strings;
- (void)processNumberData:(NSArray<NSNumber *> *)numbers;
- (NSDictionary *)analyzeData:(NSArray *)data;
- (NSString *)generateDataReport;

@end

/**
 * 网络相关的分类
 */
@interface CategoriesAndExtensionsTest (NetworkOperations)

// 网络操作方法
- (void)performNetworkRequest:(NSString *)urlString completion:(void(^)(NSData *data, NSError *error))completion;
- (void)uploadData:(NSData *)data toURL:(NSString *)urlString completion:(void(^)(BOOL success, NSError *error))completion;
- (void)downloadFileFromURL:(NSString *)urlString completion:(void(^)(NSString *filePath, NSError *error))completion;

@end

#pragma mark - 全局函数声明

// 分类相关的全局函数
NSString *CategoryTestGlobalFunction(NSString *input);
BOOL CategoryTestValidateInput(id input);
NSArray *CategoryTestProcessArray(NSArray *input);

// 分类测试常量
extern NSString * const CategoryTestNotificationName;
extern NSString * const CategoryTestErrorDomain;
extern NSInteger const CategoryTestDefaultValue;
